package com.ahem.demo.controller;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ahem.demo.entity.po.TTest;
import com.ahem.demo.service.DbService;

@Controller
public class DemoController {

	@Resource(name = "beanString")
	String beanString;

	@Autowired
	DbService dbService;

	/**
	 * 带name参数，跳转到hello界面
	 * 
	 * @param mav
	 * @return
	 */
	@RequestMapping("/helloJsp")
	public String helloJsp(Model model) {
		model.addAttribute("msg", "Hello！This is demo pages.");
		return "hello";
	}

	/**
	 * 从数据库获取数据,mybatis注解形式获取数据
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/dbData")
	public TTest dbData() {
		return dbService.findById(1);
	}

	/**
	 * 从数据库获取数据,mybatis xml形式获取数据
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/dbDataXml")
	public int dbDataXml() {
		return dbService.getRowCount(1);
	}

	/**
	 * 在 xml 文件 配置spring bean ，获取bean的值。
	 * 
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/xmlbean")
	public String xmlBean() {
		return beanString;
	}

	@RequestMapping("/weui")
	public String weui(Model model) {
		return "jquery-weui";
	}
}
